package com.bub.pay.outer.redis.email;

import jodd.mail.MailServer;
import jodd.mail.SendMailSession;
import jodd.mail.SmtpServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class EmailConfig {

	@Autowired
	private EmailProperties emailProperties;

	@Bean(name = "mailSession")
	public SendMailSession createSessionr(@Qualifier("smtpServer") SmtpServer smtpServer) {
		return smtpServer.createSession();
	}

	@Bean(name = "smtpServer")
	public SmtpServer createSmtpServer() {
		return MailServer.create().host(emailProperties.getHost()).port(emailProperties.getPort()).ssl(true)
				.property("mail.smtp.starttls.enable", "true")
				.property("mail.smtp.ssl.enable", "true")
				.auth(emailProperties.getUser(), emailProperties.getPassword()).buildSmtpMailServer();
	}
}
